package com.junzhiit.nengji.cms.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.bainaeco.framework.util.AssertUtil;
import com.junzhiit.nengji.cms.service.MemberCardService;
import com.junzhiit.nengji.cms.web.vo.MemberCardVO;
import com.junzhiit.nengji.cms.web.vo.ResultVO;

import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/memberCard")
public class MemberCardController extends BaseController {

	@Autowired
	private MemberCardService memberCardService;
	
	@ApiOperation("查询该店铺所有会员卡")
	@RequestMapping(method = RequestMethod.GET)
	public ResultVO findAll(MemberCardVO memberCardVO) {
		return memberCardService.findAll(memberCardVO);
	}
	
	@ApiOperation("根据会员卡ID查询相应信息")
	@RequestMapping(value="/find",method = RequestMethod.GET)
	public ResultVO findMemberCard(String cardId) {
		return memberCardService.findMemberCardById(cardId);
	}
	
	@ApiOperation("添加会员卡模板")
	@RequestMapping(value = "/add",method = RequestMethod.POST)
	public ResultVO add(MemberCardVO memberCardVO) {
		AssertUtil.notNull(memberCardVO.getType(), "type is required");
		AssertUtil.notNull(memberCardVO.getIsFreeCarriage(), "isFreeCarriage is required");
		AssertUtil.notNull(memberCardVO.getIsDiscount(), "isDiscount is required");
		AssertUtil.notNull(memberCardVO.getValidTimeState(), "validTimeState is required");
		AssertUtil.notNull(memberCardVO.getIsPresentCoupon(), "isPresentCoupon is required");
//		AssertUtil.notNull(memberCardVO.getIsPerfectMessage(), "isPerfectMessage is required");
//		AssertUtil.notNull(memberCardVO.getIsPhoneVerification(), "isPhoneVerification is required");
		return memberCardService.add(memberCardVO);
	}
	
	@ApiOperation("修改会员卡信息")
	@RequestMapping(value = "/update",method = RequestMethod.PUT)
	public ResultVO updateMemberCard(MemberCardVO memberCardVO) {
		return memberCardService.updateMemberCard(memberCardVO);
	}
	
	@ApiOperation("删除会员卡")
	@RequestMapping(value = "/del", method = RequestMethod.PUT)
	public ResultVO delete(String id) {
		AssertUtil.notBlank(id, "id is required.");
		return memberCardService.delete(id);
	}
	
	@ApiOperation("查询该店铺所有会员卡名称")
	@RequestMapping(value = "/name/all",method = RequestMethod.GET)
	public ResultVO findMemberCardNameAll(MemberCardVO memberCardVO) {
		return memberCardService.findMemberCardNameAll(memberCardVO);
	}
	
	@ApiOperation("查找该店铺下有规则的会员卡等级最高的信息")
	@RequestMapping(value = "/info",method = RequestMethod.GET)
	public ResultVO getMaxGrade(String sessionId) {
		AssertUtil.notBlank(sessionId, "sessionId is required.");
		return memberCardService.getMaxGrade(sessionId);
	}
	
	@ApiOperation("查找该有规则会员卡的取值范围")
	@RequestMapping(value = "/scope",method = RequestMethod.GET)
	public ResultVO getStartValue(String sessionId,String id) {
		AssertUtil.notBlank(sessionId, "sessionId is required.");
		AssertUtil.notBlank(id, "id is required.");
		return memberCardService.getScopeValue(sessionId,id);
	}
	
}
